﻿using System;
using System.Collections.Generic;
using System.Text;
using System.Data;
using Web.SystemConfig.SysCache;
using Web.SystemConfig.Models;
using Web.SystemConfig.Services;
using Web.SystemConfig.Business;
using DreamBuilder.Core.Container;

namespace Web.SystemConfig.WorkFlow
{
    public class WorkFlow
    {
        private WorkFlowDataAccess m_WorkFlowDataAccess = null;

        public WorkFlow()
        {
            if (this.m_WorkFlowDataAccess == null)
            {
                m_WorkFlowDataAccess = new WorkFlowDataAccess();
            }
        }

        /// <summary>
        /// 启动流程，在数据入库的时候，调用此方法
        /// </summary>
        /// <param name="model"></param>
        /// <param name="tableID"></param>
        /// <param name="currentUserID"></param>
        public void FlowStart(WorkFlowModel model)
        {
            //获取初始状态
            ArchiveTableEnum tableEnum = (ArchiveTableEnum)Enum.ToObject(typeof(ArchiveTableEnum), model.TableID);
            int originalStatusID = new WorkFlowManager().GetOriginalStastuIDByTableID(tableEnum);
            WorkFlowMessageStatusRule currentRule = new ArchiveCacheFacade().GetStatusRuleCache().GetRuleByOperateID(model.OperateID);
            m_WorkFlowDataAccess.AddInsertLog(model.TableID, model.RecordID, 0, model.CommentMessage, model.FromUserID, model.FromStatusID, model.FromUserID, originalStatusID, null, 1);
            string tableName = new ArchiveCacheFacade().GetStausCache().GetTableName(model.TableID);
            this.m_WorkFlowDataAccess.ProcessStatus(tableName, model.RecordID.ToString(), currentRule.ToMessageStatusID);
        }

        /// <summary>
        /// 启动流程，在数据入库的时候，调用此方法
        /// </summary>
        /// <param name="model"></param>
        /// <param name="tableID"></param>
        /// <param name="currentUserID"></param>
        public void FlowStart(WorkFlowModel model, bool isSinglewell)
        {
            //获取初始状态
            ArchiveTableEnum tableEnum = (ArchiveTableEnum)Enum.ToObject(typeof(ArchiveTableEnum), model.TableID);
            int originalStatusID = new WorkFlowManager().GetOriginalStastuIDByTableID(tableEnum);

            DataTable operateLogList = null;
            //获取所有操作日志
            string returnMsg = this.m_WorkFlowDataAccess.GetFlowLog(model.TableID, model.RecordID, out operateLogList);
            if (!string.IsNullOrEmpty(returnMsg))
            {
                throw new Exception("获取流程记录失败");
            }
            //若没有录入日志，添加录入日志
            if (operateLogList == null || operateLogList.Rows.Count == 0)
            {
                WorkFlowMessageStatusRule currentRule = new ArchiveCacheFacade().GetStatusRuleCache().GetRuleByOperateID(model.OperateID);
                m_WorkFlowDataAccess.AddInsertLog(model.TableID, model.RecordID, 0, model.CommentMessage, model.FromUserID, model.FromStatusID, model.FromUserID, originalStatusID, null, 1);
                string tableName = new ArchiveCacheFacade().GetStausCache().GetTableName(model.TableID);
                this.m_WorkFlowDataAccess.ProcessStatus(tableName, model.RecordID.ToString(), model.FromStatusID);
            }
        }

        /// <summary>
        /// 驱动流程
        /// </summary>
        /// <param name="model"></param>
        /// <param name="process">是向前还是向后驱动</param>
        public void FlowProcess(WorkFlowModel model)
        {
            if (model.OperateLogID == Guid.Empty)
            {
                throw new Exception("所传入的参数OperateLogID不能为空");
            }
            DataTable operateLogList = null;
            //获取所有操作日志
            string returnMsg = this.m_WorkFlowDataAccess.GetFlowLog(model.TableID, model.RecordID, out operateLogList);
            if (!string.IsNullOrEmpty(returnMsg))
            {
                throw new Exception("获取流程记录失败");
            }

            WorkFlowMessageStatusRule currentRule = new ArchiveCacheFacade().GetStatusRuleCache().GetRuleByOperateID(model.OperateID);
            string tableName = new ArchiveCacheFacade().GetStausCache().GetTableName(model.TableID);
            //判断是否有日志，若没有日志，加上录入日志和操作日志
            if (operateLogList == null || operateLogList.Rows.Count == 0)
            {
                //添加录入日志
                this.m_WorkFlowDataAccess.AddInsertLog(model.TableID, model.RecordID, 0, "", model.FromUserID, model.FromStatusID, model.FromUserID, model.FromStatusID, model.FromUserID.ToString(), 0);
                //驱动流程
                List<SysUser> userList = this.GetUsersByRoleID(currentRule.ToRoleID.ToString());
                if (userList != null && userList.Count > 0)
                {
                    if (userList.Count > 1)
                    {
                        //记录操作日志
                        this.m_WorkFlowDataAccess.AddNewFlowLog(model.TableID, model.RecordID, model.OperateID, model.CommentMessage, model.FromUserID, model.FromStatusID, userList[0].UserID, currentRule.ToMessageStatusID, true);
                        for (int index = 1; index < userList.Count; index++)
                        {
                            //记录操作日志
                            this.m_WorkFlowDataAccess.AddNewFlowLog(model.TableID, model.RecordID, model.OperateID, model.CommentMessage, model.FromUserID, model.FromStatusID, userList[index].UserID, currentRule.ToMessageStatusID, false);
                        }
                        //修改业务表状态
                        this.m_WorkFlowDataAccess.ProcessStatus(tableName, model.RecordID.ToString(), currentRule.ToMessageStatusID);
                    }
                    else
                    {
                        //记录操作日志
                        this.m_WorkFlowDataAccess.AddNewFlowLog(model.TableID, model.RecordID, model.OperateID, model.CommentMessage, model.FromUserID, model.FromStatusID, userList[0].UserID, currentRule.ToMessageStatusID, true);
                        //修改业务表状态
                        this.m_WorkFlowDataAccess.ProcessStatus(tableName, model.RecordID.ToString(), currentRule.ToMessageStatusID);
                    }
                }
                else
                {
                    throw new Exception("您所操作的审核组没有用户");
                }
                return;
            }

            //获取最后那条流程
            DataRow[] drArr = operateLogList.Select("IsLast=1");
            //判断是否存在流程，若不存在，表示流程已经终结,不需要处理
            if (drArr != null)
            {
                if (drArr.Length == 1)
                {
                    string LastFromUserID = drArr[0]["FromUserID"].ToString();
                    string LastToUserID = drArr[0]["ToUserID"].ToString();
                    int LastOperateID = int.Parse(drArr[0]["OperateID"].ToString());
                    WorkFlowMessageStatusRule LastRule = new ArchiveCacheFacade().GetStatusRuleCache().GetRuleByOperateID(LastOperateID);
                    //判断是否录入日志
                    //录入日志的特点是OperateID=0  IsLast=1  FromStatusID=ToStatusID  FromUserID=ToUserID
                    if (LastOperateID == 0 && LastFromUserID == LastToUserID)
                    {
                        //先自动签收流程
                        this.SignData(model);
                        //然后驱动流程
                        List<SysUser> userList = this.GetUsersByRoleID(currentRule.ToRoleID.ToString());
                        if (userList != null && userList.Count > 0)
                        {
                            if (userList.Count > 1)
                            {
                                //记录操作日志
                                this.m_WorkFlowDataAccess.AddNewFlowLog(model.TableID, model.RecordID, model.OperateID, model.CommentMessage, model.FromUserID, model.FromStatusID, userList[0].UserID, currentRule.ToMessageStatusID, true);
                                for (int index = 1; index < userList.Count; index++)
                                {
                                    //记录操作日志
                                    this.m_WorkFlowDataAccess.AddNewFlowLog(model.TableID, model.RecordID, model.OperateID, model.CommentMessage, model.FromUserID, model.FromStatusID, userList[index].UserID, currentRule.ToMessageStatusID, false);
                                }
                                //修改业务表状态
                                this.m_WorkFlowDataAccess.ProcessStatus(tableName, model.RecordID.ToString(), currentRule.ToMessageStatusID);
                            }
                            else
                            {
                                //记录操作日志
                                this.m_WorkFlowDataAccess.AddNewFlowLog(model.TableID, model.RecordID, model.OperateID, model.CommentMessage, model.FromUserID, model.FromStatusID, userList[0].UserID, currentRule.ToMessageStatusID, true);
                                //修改业务表状态
                                this.m_WorkFlowDataAccess.ProcessStatus(tableName, model.RecordID.ToString(), currentRule.ToMessageStatusID);
                            }
                        }
                        else
                        {
                            throw new Exception("您所操作的审核组没有用户");
                        }
                        return;
                    }

                    //判断是否打回去的流程
                    if (LastToUserID != model.FromUserID.ToString())//上一条流程的审核者应该是这条流程的申报者
                    {
                        throw new Exception("流程有异常");
                    }
                    //判断流程是否LastRule和currentRule返回
                    if (LastRule.ToRoleID == currentRule.FromRoleID && LastRule.FromRoleID == currentRule.ToRoleID && LastToUserID == model.FromUserID.ToString())
                    {
                        //此时表示是打回去的流程
                        this.m_WorkFlowDataAccess.AddNewFlowLog(model.TableID, model.RecordID, model.OperateID, model.CommentMessage, model.FromUserID, model.FromStatusID, new Guid(LastFromUserID), currentRule.ToMessageStatusID, true);
                        //修改业务表状态
                        this.m_WorkFlowDataAccess.ProcessStatus(tableName, model.RecordID.ToString(), currentRule.ToMessageStatusID);
                    }
                    else
                    {
                        List<SysUser> userList = this.GetUsersByRoleID(currentRule.ToRoleID.ToString());
                        if (userList.Count > 0)
                        {
                            if (userList.Count > 1)
                            {
                                //记录操作日志
                                this.m_WorkFlowDataAccess.AddNewFlowLog(model.TableID, model.RecordID, model.OperateID, model.CommentMessage, model.FromUserID, model.FromStatusID, userList[0].UserID, currentRule.ToMessageStatusID, true);
                                for (int index = 1; index < userList.Count; index++)
                                {
                                    //记录操作日志
                                    this.m_WorkFlowDataAccess.AddNewFlowLog(model.TableID, model.RecordID, model.OperateID, model.CommentMessage, model.FromUserID, model.FromStatusID, userList[index].UserID, currentRule.ToMessageStatusID, false);
                                }
                                //修改业务表状态
                                this.m_WorkFlowDataAccess.ProcessStatus(tableName, model.RecordID.ToString(), currentRule.ToMessageStatusID);
                            }
                            else
                            {
                                //记录操作日志
                                this.m_WorkFlowDataAccess.AddNewFlowLog(model.TableID, model.RecordID, model.OperateID, model.CommentMessage, model.FromUserID, model.FromStatusID, userList[0].UserID, currentRule.ToMessageStatusID, true);
                                //修改业务表状态
                                this.m_WorkFlowDataAccess.ProcessStatus(tableName, model.RecordID.ToString(), currentRule.ToMessageStatusID);
                            }
                        }
                        else
                        {
                            throw new Exception("您所操作的审核组没有用户");
                        }
                    }
                }
                else
                {
                    throw new Exception("该数据存在不止一条流程");
                }
            }
        }

        /// <summary>
        /// 若传递了参数userID，则表示发送流程到个人。
        /// </summary>
        /// <param name="model"></param>
        /// <param name="userID"></param>
        public void FlowProcess(WorkFlowModel model, Guid userID)
        {
            if (userID == Guid.Empty)
            {
                this.FlowProcess(model);
            }
            else
            {
                DataTable operateLogList = null;
                //获取所有操作日志
                string returnMsg = this.m_WorkFlowDataAccess.GetFlowLog(model.TableID, model.RecordID, out operateLogList);
                if (!string.IsNullOrEmpty(returnMsg))
                {
                    throw new Exception("获取流程记录失败");
                }
                //判断是否有新增日志，若没有，添加新增日志
                if (operateLogList == null || operateLogList.Rows.Count == 0)
                {
                    //添加录入日志
                    this.m_WorkFlowDataAccess.AddInsertLog(model.TableID, model.RecordID, 0, "", model.FromUserID, model.FromStatusID, model.FromUserID, model.FromStatusID, model.FromUserID.ToString(), 0);
                }
                WorkFlowMessageStatusRule currentRule = new ArchiveCacheFacade().GetStatusRuleCache().GetRuleByOperateID(model.OperateID);
                string tableName = new ArchiveCacheFacade().GetStausCache().GetTableName(model.TableID);
                //记录操作日志
                this.m_WorkFlowDataAccess.AddNewFlowLog(model.TableID, model.RecordID, model.OperateID, model.CommentMessage, model.FromUserID, model.FromStatusID, userID, currentRule.ToMessageStatusID, true);
                //驱动业务表状态
                this.m_WorkFlowDataAccess.ProcessStatus(tableName, model.RecordID.ToString(), currentRule.ToMessageStatusID);
            }
        }

        public void FlowProcess(WorkFlowModel model, List<Guid> toUserList)
        {
            if (toUserList == null || toUserList.Count == 0)
            {
                throw new Exception("流程接受者为空");
            }

            DataTable operateLogList = null;
            //获取所有操作日志
            string returnMsg = this.m_WorkFlowDataAccess.GetFlowLog(model.TableID, model.RecordID, out operateLogList);
            if (!string.IsNullOrEmpty(returnMsg))
            {
                throw new Exception("获取流程记录失败");
            }
            //判断是否有新增日志，若没有，添加新增日志
            if (operateLogList == null || operateLogList.Rows.Count == 0)
            {
                //添加录入日志
                this.m_WorkFlowDataAccess.AddInsertLog(model.TableID, model.RecordID, 0, "", model.FromUserID, model.FromStatusID, model.FromUserID, model.FromStatusID, model.FromUserID.ToString(), 0);
            }
            WorkFlowMessageStatusRule currentRule = new ArchiveCacheFacade().GetStatusRuleCache().GetRuleByOperateID(model.OperateID);
            string tableName = new ArchiveCacheFacade().GetStausCache().GetTableName(model.TableID);

            if (toUserList.Count >= 1)
            {
                //记录操作日志
                this.m_WorkFlowDataAccess.AddNewFlowLog(model.TableID, model.RecordID, model.OperateID, model.CommentMessage, model.FromUserID, model.FromStatusID, toUserList[0], currentRule.ToMessageStatusID, true);
                for (int index = 1; index < toUserList.Count; index++)
                {
                    //记录操作日志
                    this.m_WorkFlowDataAccess.AddNewFlowLog(model.TableID, model.RecordID, model.OperateID, model.CommentMessage, model.FromUserID, model.FromStatusID, toUserList[index], currentRule.ToMessageStatusID, false);
                }
                //修改业务表状态
                this.m_WorkFlowDataAccess.ProcessStatus(tableName, model.RecordID.ToString(), currentRule.ToMessageStatusID);

                //驱动业务表状态
                this.m_WorkFlowDataAccess.ProcessStatus(tableName, model.RecordID.ToString(), currentRule.ToMessageStatusID);
            }
        }

        /// <summary>
        /// 关闭流程
        /// </summary>
        /// <param name="model"></param>
        public void FlowFinish(WorkFlowModel model)
        {
            if (model.TableID == 0)
            {
                throw new Exception("所传入的参数TableID不能为空");
            }

            if (model.RecordID == Guid.Empty)
            {
                throw new Exception("所传入的参数RecordID不能为空");
            }

            this.m_WorkFlowDataAccess.FinishFlowLog(model.TableID, model.RecordID.ToString(), model.FromUserID);
        }

        /// <summary>
        /// 系统自动关闭流程
        /// </summary>
        /// <param name="model"></param>
        /// <param name="isSystem"></param>
        public void FlowFinish(ArchiveTableEnum tableEnum, string recordID)
        {
            int tableID = (int)tableEnum;
            this.m_WorkFlowDataAccess.FinishFlowLog(tableID, recordID);
        }

        //public WorkFlowModel GetCurrentWorkFlowModel(int tableID, Guid recordID)
        //{
        //    WorkFlowModel rtnModel = null;
        //    DataTable dt = null;
        //    string strMsg = new WorkFlowDataAccess().GetFlowLogIsLast(tableID, recordID, out dt);
        //    if (string.IsNullOrEmpty(strMsg))
        //    {
        //        if (dt != null && dt.Rows.Count > 0)
        //        {
        //            ///只会有一条数据
        //            rtnModel = new WorkFlowModel();
        //            DataRow dr = dt.Rows[0];
        //            rtnModel.CommentMessage = dr["COMMENTMESSAGE"].ToString();
        //            rtnModel.CurrentStatus = int.Parse(dr["FROMSTATUSID"].ToString());
        //            rtnModel.CurrentUserID = new Guid(dr["FROMUSERID"].ToString());
        //            //rtnModel.OperateID = int.Parse(dr[""].ToString());
        //            rtnModel.OperateLogID = new Guid(dr["OPERATELOGID"].ToString());
        //            rtnModel.RecordID = new Guid(dr["RECORDID"].ToString());
        //            rtnModel.TableID = int.Parse(dr["TABLEID"].ToString());
        //            rtnModel.ToStatus = int.Parse(dr["TOSTATUSID"].ToString());
        //            rtnModel.ToUserID = new Guid(dr["TOUSERID"].ToString());
        //        }
        //    }

        //    return rtnModel;
        //}

        /// <summary>
        /// 签收数据
        /// </summary>
        /// <param name="model"></param>
        /// <param name="signUserID"></param>
        public void SignData(WorkFlowModel model)
        {
            //如果流程已经走完，需要在此做流程终结
            //判断的依据是，当前数据的状态是否还存在操作
            List<WorkFlowMessageStatusRule> ruleListCache = new ArchiveCacheFacade().GetStatusRuleCache().GetRuleByStatusID(model.FromStatusID);
            if (ruleListCache != null && ruleListCache.Count > 0)
            {
                //还存在操作，不能终结流程
                m_WorkFlowDataAccess.SignData(model.FromUserID, model.TableID, model.RecordID.ToString());
            }
            else
            {
                //不存在操作，需要终结流程
                m_WorkFlowDataAccess.SignData(model.FromUserID, model.TableID, model.RecordID.ToString());
                this.FlowFinish(model);
            }
        }

        public bool AutoSignData(ArchiveTableEnum tableEnum, Guid currentUserID)
        {
            WorkFlowMessageStatus finnalStatus = new ArchiveCacheFacade().GetStatusRuleCache().GetFinnalMessageStatusID(tableEnum);
            string tableName = new ArchiveCacheFacade().GetStausCache().GetTableName((int)tableEnum);
            if (finnalStatus != null)
            {
                return this.m_WorkFlowDataAccess.AutoSignData(currentUserID, (int)tableEnum, tableName, finnalStatus.StatusID);
            }
            else
            {
                return false;
            }
        }

        /// <summary>
        /// 代办
        /// </summary>
        /// <param name="tableName"></param>
        /// <param name="userID"></param>
        /// <param name="beginNum"></param>
        /// <param name="count"></param>
        /// <param name="sum"></param>
        /// <returns></returns>
        public DataTable GetAgent(ArchiveTableEnum tableEnum, string userID, int beginNum, int count, string filter, ref int sum, FilterSortEnum sort = FilterSortEnum.OrderByOperateTimeACS)
        {
            string tableName = new ArchiveCacheFacade().GetStausCache().GetTableName((int)tableEnum);
            return m_WorkFlowDataAccess.GetAgent(tableEnum, tableName, userID, beginNum, count, filter, ref sum, sort);
        }

        /// <summary>
        /// 已办
        /// </summary>
        /// <param name="tableName"></param>
        /// <param name="userID"></param>
        /// <param name="beginNum"></param>
        /// <param name="count"></param>
        /// <param name="sum"></param>
        /// <returns></returns>
        public DataTable GetDone(ArchiveTableEnum tableEnum, string userID, int beginNum, int count, string filter, ref int sum, FilterSortEnum sort = FilterSortEnum.OrderByOperateTimeACS)
        {
            string tableName = new ArchiveCacheFacade().GetStausCache().GetTableName((int)tableEnum);
            return m_WorkFlowDataAccess.GetDone(tableEnum, tableName, userID, beginNum, count, filter, ref sum, sort);
        }

        /// <summary>
        /// 获取入库的所有数据
        /// </summary>
        /// <param name="tableEnum"></param>
        /// <param name="tableName"></param>
        /// <param name="userID"></param>
        /// <param name="beginNum"></param>
        /// <param name="count"></param>
        /// <param name="sum"></param>
        /// <returns></returns>
        public DataTable GetTotal(ArchiveTableEnum tableEnum, int beginNum, int count, out int sum, string filter, string userID)
        {
            int finishStatusID = new ArchiveCacheFacade().GetStatusRuleCache().GetFinishStatus((int)tableEnum);
            string tableName = new ArchiveCacheFacade().GetStausCache().GetTableName((int)tableEnum);
            return this.m_WorkFlowDataAccess.GetTotal(tableEnum, tableName, userID, beginNum, count, out sum, finishStatusID, filter);
        }

        public DataTable GetTotalAll(ArchiveTableEnum tableEnum, string filter, string userID = "")
        {
            int finishStatusID = new ArchiveCacheFacade().GetStatusRuleCache().GetFinishStatus((int)tableEnum);
            string tableName = new ArchiveCacheFacade().GetStausCache().GetTableName((int)tableEnum);
            return this.m_WorkFlowDataAccess.GetTotalAll(tableEnum, tableName, userID, finishStatusID, filter);
        }

        /// <summary>
        /// 获取浏览数据权限和操作权限
        /// </summary>
        /// <param name="tableEnum"></param>
        /// <param name="userID"></param>
        /// <param name="recordID"></param>
        /// <param name="canView">返回能否浏览</param> 
        /// <param name="canOperate">返回能否操作</param>
        /// <returns></returns>
        public string GetPrivilege(ArchiveTableEnum tableEnum, string userID, string recordID, ref bool canEdit, ref bool canView, ref bool canOperate)
        {
            string rtnStr = string.Empty;
            DataTable oDataTable = null;
            string msg = this.m_WorkFlowDataAccess.GetAllFlowLog((int)tableEnum, recordID, out oDataTable);
            if (!string.IsNullOrEmpty(msg))
            {
                canView = false;
                canEdit = false;
                canOperate = false;
                rtnStr = "没有找到相应的操作日志";
            }
            else
            {
                if (oDataTable.Rows.Count == 1 && oDataTable.Rows[0]["fromUserID"] == oDataTable.Rows[0]["toUserID"] && oDataTable.Rows[0]["toUserID"].ToString() == userID)
                {
                    canView = true;
                    canOperate = true;
                    return rtnStr;
                }

                DataRow[] canViewDrArr = oDataTable.Select("toUserID='" + userID + "' and signUserID='" + userID + "'");
                DataRow[] canEditDrArr = oDataTable.Select("fromUserID='" + userID + "' and toUserID='" + userID + "' and signUserID='" + userID + "'");
                DataRow[] canOperateDrArr = oDataTable.Select("toUserID='" + userID + "' and signUserID='" + userID + "' and IsLast=1");

                if (canViewDrArr != null && canViewDrArr.Length > 0)
                {
                    canView = true;
                }

                if (canOperateDrArr != null && canOperateDrArr.Length > 0)
                {
                    canOperate = true;
                }

                if (canOperate)
                {
                    if (canEditDrArr != null && canEditDrArr.Length > 0)
                    {
                        canEdit = true;
                    }
                }
            }
            return rtnStr;
        }

        /// <summary>
        /// 通过角色获取当前角色所有成员
        /// </summary>
        /// <param name="roleID"></param>
        /// <returns></returns>
        private List<Models.SysUser> GetUsersByRoleID(string roleID)
        {
            List<Models.SysUser> rtnListSysUser = null;
            DataTable userdt = this.m_WorkFlowDataAccess.GetUsersByRoleID(roleID);
            if (userdt != null && userdt.Rows.Count > 0)
            {
                rtnListSysUser = new List<Models.SysUser>();
                foreach (DataRow dr in userdt.Rows)
                {
                    Models.SysUser user = new Models.SysUser();
                    user.RoleID = int.Parse(dr["role_id"].ToString());
                    user.UserID = new Guid(dr["User_ID"].ToString());
                    user.UserName = dr["User_Name"].ToString();
                    rtnListSysUser.Add(user);
                }
            }

            return rtnListSysUser;
        }

        /// <summary>
        /// 获取角色下、单位下所有用户
        /// </summary>
        /// <param name="roleID"></param>
        /// <param name="orgID"></param>
        /// <returns></returns>
        private List<Models.SysUser> GetUsersByRoleIDAndOrgID(string roleID, string orgID)
        {
            List<Models.SysUser> rtnListSysUser = null;
            DataTable userdt = this.m_WorkFlowDataAccess.GetUsersByRoleIDAndOrgID(roleID, orgID);
            if (userdt != null && userdt.Rows.Count > 0)
            {
                rtnListSysUser = new List<Models.SysUser>();
                foreach (DataRow dr in userdt.Rows)
                {
                    Models.SysUser user = new Models.SysUser();
                    user.RoleID = int.Parse(dr["role_id"].ToString());
                    user.UserID = new Guid(dr["User_ID"].ToString());
                    user.UserName = dr["User_Name"].ToString();
                    rtnListSysUser.Add(user);
                }
            }

            return rtnListSysUser;
        }

        /// <summary>
        /// 获取操作日志
        /// </summary>
        /// <param name="tableEnum"></param>
        /// <param name="recordID"></param>
        /// <returns></returns>
        public DataTable GetOperateLogList(ArchiveTableEnum tableEnum, string recordID)
        {
            DataTable rtnDateTable = null;
            string message = this.m_WorkFlowDataAccess.GetAllFlowLog((int)tableEnum, recordID, out rtnDateTable);
            if (!string.IsNullOrEmpty(message))
            {
                rtnDateTable = null;
            }
            return rtnDateTable;
        }
    }

    public enum FilterSortEnum
    {
        OrderByOperateTimeACS = 0,
        OrderByOperateTimeDESC = 1,
        OrderByCreateTimeASC = 2,
        OrderByCreateTimeDESC = 3
    }
}